<!DOCTYPE html>
<html>
<head>
    <meta name="layout" content="main"/>
    <g:set var="entityName" value="${message(code: 'vehicle.label', default: 'Vehicle')}"/>
    <title>新增预警配置</title>
</head>

<body>
<div class="small-header">
    <div class="hpanel">
        <div class="panel-body">
            <div id="hbreadcrumb" class="pull-right">
                <ol class="hbreadcrumb breadcrumb">
                    <li>PLS CINDATA</li>
                    <li>
                        <g:link controller="riskWarningConfig" action="index">列表</g:link>
                    </li>
                    <li class="active">
                        <span>新增预警配置</span>
                    </li>
                </ol>
            </div>

            <h2 class="font-light m-b-xs">
                新增预警配置
            </h2>
        </div>
    </div>
</div>

<g:form action="save" class="myForm">
    <g:if test="${flash.message}">
        <div class="message alert alert-info" role="status">${flash.message}</div>
    </g:if>
    <g:hasErrors bean="${this.riskwaringconfig}">
        <ul class="errors" role="alert">
            <g:eachError bean="${this.riskwaringconfig}" var="error">
                <li <g:if test="${error in org.springframework.validation.FieldError}">data-field-id="${error.field}"</g:if>><g:message
                        error="${error}"/></li>
            </g:eachError>
        </ul>
    </g:hasErrors>

    <div class="content animate-panel">
        <div class="row">
            <div class="hpanel hblue">
                <div class="panel-heading">
                    配置信息
                </div>

                <div class="panel-body form-horizontal">
                    <div class="form-group">
                        <label class="col-md-2 control-label is-required">名称</label>
                        <div class="col-md-3">
                            <g:textField class="form-control" type="text" name="name" id="name" value="${this?.riskWarningConfig?.name}"/>
                        </div>

                        <label class="col-md-2 control-label is-required">类型</label>
                        <div class="col-md-3">
                            <g:select class="form-control" name="type" id="type" from="${com.next.RiskWarningConfig.constrainedProperties.type.inList}"
                                value="${this?.riskWarningConfig?.type}"/>
                        </div>
                    </div>

                    <div class="form-group">
                        <label class="col-md-2 control-label is-required">状态</label>
                        <div class="col-md-3">
                            <g:select class="form-control m-b" name="status" id="status" from="${[[name:'禁用',value:0]]}" optionValue="name" optionKey="value" value="0"/>
                        </div>
                    </div>

                    <div class="form-group">
                        <label class="col-md-2 control-label">执行周期</label>
                        <div class="col-md-3">
                            <g:select class="form-control" name="duration" id="duration" from="${[[name:'周末',value:'week'],[name:'月末',value:'month'],[name:'季末',value:'quarter'],[name:'年末',value:'year']]}" optionKey="value" optionValue="name" value="${this?.riskWarningConfig?.duration}" noSelection="${['': '请选择执行周期']}"/>
                        </div>
                        <label class="col-md-2 control-label">工作流</label>
                        <div class="col-md-3">
                            <g:select class="form-control m-b" name="workflow" id="workflow" from="${com.next.Workflow.list()}" optionValue="name" optionKey="id" value="${this?.riskWarningConfig?.workflow?.id}" noSelection="${['': '请选择工作流']}"/>
                        </div>
                    </div>

                    <div class="form-group">

                        <label class="col-md-2 control-label is-required">对象</label>
                        <div class="col-md-3">
                            <g:select class="form-control" name="sourceClassType" id="sourceClassType" from="${com.next.RiskWarningConfig.constrainedProperties.sourceClassType.inList}"
                                value="${this?.riskWarningConfig?.sourceClassType}"/>
                        </div>

                        %{--<label class="col-md-2 control-label is-required">监测预警类型</label>--}%
                        %{--<div class="col-md-3">--}%
                            %{--<g:select class="form-control m-b" name="warningType" id="warningType" from="${com.next.dictionary.RiskWarningTypeDict.list()}" optionValue="name" optionKey="id" value="${this?.riskWarningConfig?.warningType?.id}" noSelection="${['': '请选择监测预警类型']}"/>--}%
                        %{--</div>--}%
                    </div>

                    <div class="form-group">
                        <label class="col-md-2 control-label">规则关系</label>
                        <div class="col-md-3">
                            <g:select class="form-control" name="isAndRelation" id="isAndRelation" optionKey="value" optionValue="name" from="${[[name:'并且',value: true],[name:'或者',value: false]]}" value="${riskWarningConfig?.isAndRelation}"/>
                        </div>

                        <label class="col-md-2 control-label is-required">最大条数</label>
                        <div class="col-md-3">
                            <g:field class="form-control" type="number" name="limitCounts" id="limitCounts" min="1" max="100" required="" value="${this?.riskWarningConfig?.limitCounts}"/>
                        </div>
                    </div>

                    <div class="form-group">
                        <label class="col-md-2 control-label">描述</label>
                        <div class="col-md-3">
                            <g:textArea name="description" id="description" value="${this.riskWarningConfig?.description}" class="form-control textarea" rows="3" cols="15"/>
                        </div>

                        <label class="col-md-2 control-label">图表描述</label>
                        <div class="col-md-3">
                            <g:textArea name="chartDescription" id="chartDescription" value="${this.riskWarningConfig?.chartDescription}" class="form-control textarea" rows="3" cols="15"/>
                        </div>
                    </div>

                    <div class="form-group">
                        <label class="col-md-2 control-label">图表状态</label>
                        <div class="col-md-3">
                            <g:select class="form-control m-b" name="chartStatus" id="chartStatus" from="${[[name:'启用',value:1],[name:'禁用',value:0]]}" optionValue="name" optionKey="value" value="0"/>
                        </div>

                        <label class="col-md-2 control-label">图表顺序</label>
                        <div class="col-md-3">
                            <g:textField class="form-control" type="chartSequence" name="chartSequence" id="chartSequence" value="${this?.riskWarningConfig?.chartSequence}"/>
                        </div>
                    </div>

                    <div class="form-group">
                        <label class="col-md-2 control-label">图表类型</label>
                        <div class="col-md-3">
                            <g:select class="form-control" name="chartType" id="chartType" from="${com.next.RiskWarningConfig.constrainedProperties.chartType.inList}"
                                value="${this?.riskWarningConfig?.chartType}"/>
                        </div>

                        <label class="col-md-2 control-label">列表名称</label>
                        <div class="col-md-3">
                            <g:textField class="form-control" type="text" name="sourceAction" id="sourceAction" value="${this?.riskWarningConfig?.sourceAction}"/>
                        </div>
                    </div>
                    
                    <div class="form-group">
                        <label class="col-md-2 control-label">图表查询</label>
                        <div class="col-md-8">
                            <g:textArea class="form-control" type="chartSql" name="chartSql" id="chartSql" value="${this?.riskWarningConfig?.chartSql}" rows="3" cols="15"/>
                        </div>
                    </div>
                </div>
            </div>
        </div>

        <div class="row" id="collateral">
            <div class="hpanel hblue">
                <div class="panel-heading">
                    押品条件
                </div>

                <div class="panel-body form-horizontal">

                </div>

            </div>
        </div>

        <div class="row" id="mortgage">
            <div class="hpanel hblue">
                <div class="panel-heading">
                    贷款条件
                </div>

                <div class="panel-body form-horizontal">
                    <div class="form-group">
                        <label class="col-md-2 control-label">客户类型</label>
                        <div class="col-md-3">
                            <g:select class="form-control" name="contactType" id="contactType" from="${com.next.RiskWarningConfig.constrainedProperties.contactType.inList}"
                                value="${this?.riskWarningConfig?.contactType}" noSelection="${['': '请选择客户类型']}"/>
                        </div>





                        <label class="col-md-2 control-label">抵押类型</label>
                        <div class="col-md-3">
                            <g:select class="form-control" name="mortgageType" id="mortgageType" from="${com.next.MortgageType.list()}"
                                valueMessagePrefix="status" optionKey="id" optionValue="name" value="${this?.riskWarningConfig?.mortgageType?.id}" noSelection="${['': '请选择抵押类型']}"/>
                        </div>
                    </div>
                </div>
            </div>
        </div>

        <div class="row" id="contact">
            <div class="hpanel hblue">
                <div class="panel-heading">
                    借款人条件
                </div>

                <div class="panel-body form-horizontal">
                    <div class="form-group">
                        <label class="col-sm-2 control-label">征信评分</label>
                        <div class="col-sm-3  input-group">
                            <input type="text" class=" form-control" placeholder="请输入下限" id="creditScoreStart" maxlength="6" value="${this?.riskWarningConfig?.creditScoreStart}" name="creditScoreStart" />
                            <span class="input-group-addon">至</span>
                            <input type="text" class="form-control " placeholder="请输入上限" id="creditScoreEnd" maxlength="6" value="${this?.riskWarningConfig?.creditScoreEnd}" name="creditScoreEnd" />
                        </div>

                        <!-- <label class="col-sm-2 control-label">年龄</label>
                        <div class="col-sm-3  input-group">
                            <input type="text" class=" form-control" placeholder="请输入下限" id="ageStart" maxlength="6" value="${params?.creditScoreStart}" name="ageStart" />
                            <span class="input-group-addon">至</span>
                            <input type="text" class="form-control " placeholder="请输入上限" id="ageEnd" maxlength="6" value="${params?.creditScoreEnd}" name="ageEnd" />
                        </div> -->
                    </div>
                </div>
            </div>
        </div>

        <div class="row" id="community">
            <div class="hpanel hblue">
                <div class="panel-heading">
                    小区条件
                </div>

                <div class="panel-body form-horizontal">
                    <div class="form-group">
                        <label class="col-md-2 control-label">城市</label>
                        <div class="col-md-3">
                            <g:select class="form-control" name="city" id="city" from="${com.next.City.list()}"
                                valueMessagePrefix="status" optionKey="id" optionValue="name" value="${this?.riskWarningConfig?.city?.id}" noSelection="${['': '请选择城市']}"/>
                        </div>

                        <label class="col-md-2 control-label">行政区</label>
                        <div class="col-md-3">
                            <g:select class="form-control" name="district" id="district" from="${com.next.District.list()}"
                                valueMessagePrefix="status" optionKey="id" optionValue="name" value="${this?.riskWarningConfig?.district?.id}" noSelection="${['': '请选择行政区']}"/>
                        </div>
                    </div>
                </div>
            </div>
        </div>
        
        <div class="row" id="account">
            <div class="hpanel hblue">
                <div class="panel-heading">
                    机构条件
                </div>

                <div class="panel-body form-horizontal">
                    <div class="form-group">


                    </div>

                    <div class="form-group">
                        <label class="col-md-2 control-label">信用等级</label>
                        <div class="col-md-3">
                            <g:textField class="form-control" type="text" name="creditLevel" id="creditLevel" value="${this.riskWarningConfig?.creditLevel}" placeholder="请输入信用等级"/>
                        </div>
                    </div>
                </div>
            </div>
        </div>

        <div class="row">
            <div class="form-group">
                <div class="col-md-3 col-md-offset-6">
                    <button class="btn btn-info submit" type="button">保存</button>
                </div>
            </div>
        </div>
    </div>
</g:form>


<script>
    
    var sourceClassType = $("#sourceClassType").val()
    changeSourceClassType(sourceClassType)

    $("#sourceClassType").change(function() 
    {
        var sourceClassType = $(this).find("option:selected").text();
        changeSourceClassType(sourceClassType)
    });

    function changeSourceClassType(sourceClassType)
    {
        if (sourceClassType == "押品") 
        {
            $('#collateral').removeClass('hide');
            $('#mortgage').addClass('hide');
            $('#contact').addClass('hide');
            $('#community').addClass('hide');
            $('#account').addClass('hide');
        }
        if (sourceClassType == "贷款") 
        {
            $('#mortgage').removeClass('hide');
            $('#collateral').addClass('hide');
            $('#contact').addClass('hide');
            $('#community').addClass('hide');
            $('#account').addClass('hide');
        }
        if (sourceClassType == "借款人") 
        {
            $('#contact').removeClass('hide');
            $('#collateral').addClass('hide');
            $('#mortgage').addClass('hide');
            $('#community').addClass('hide');
            $('#account').addClass('hide');
        }
        if (sourceClassType == "小区") 
        {
            $('#community').removeClass('hide');
            $('#collateral').addClass('hide');
            $('#mortgage').addClass('hide');
            $('#contact').addClass('hide');
            $('#account').addClass('hide');
        }
        if (sourceClassType == "机构") 
        {
            $('#account').removeClass('hide');
            $('#community').addClass('hide');
            $('#collateral').addClass('hide');
            $('#mortgage').addClass('hide');
            $('#contact').addClass('hide');
        }
    }

    $("#city").bind("change", function(){
        $("#district option").remove();
        $("#s2id_district span:first").html("请选择行政区");
        var city = $("#city").val()
        $("#district").append("<option value='' >请选择行政区</option>")
        if(city=='-1'){
            return
        }
        $.ajax({
            url: "/district/getDistrictByCityId",
            type: "POST",
            data: {'city': city} ,
            success: function(result){
                console.log(result)
                for(var i=0; i < result.districtList.length; i++){
                    $("#district").append("<option value=" + result.districtList[i].id + ">" + result.districtList[i].name + "</option>")
                }
            }
        });
    });
    $("#city").change();

    $(".submit").click(function() {

        var name = $("#name").val()
        if(!name)
        {
            toastr.error('请输入名称！');
            return;
        }
        var type = $("#type").val()
        if(!type)
        {
            toastr.error('请输入类型！');
            return;
        }
        var status = $("#status").val()
        if(!status)
        {
            toastr.error('请输入状态！');
            return;
        }
        var sourceClassType = $("#sourceClassType").val()
        if(!sourceClassType)
        {
            toastr.error('请输入对象！');
            return;
        }
        // var warningType = $("#warningType").val()
        // if(!warningType)
        // {
        //     toastr.error('请输入监测预警类型！');
        //     return;
        // }
        var limitCounts = $("#limitCounts").val()
        if(!limitCounts)
        {
            toastr.error('请输入最大条数！');
            return;
        }
        $(".myForm").submit();
    })

</script>
</body>
</html>
